package Rangel.common.world.entity;

import Rangel.policeforce.extaction.clear.GuideLine;
import rescuecore2.standard.entities.*;
import rescuecore2.worldmodel.EntityID;

import java.util.*;


public class Path extends ArrayList<Road> implements Comparable {
    private static final long serialVersionUID = 8598632115217843761L;//路径是道路的ArrayList

    private List<Entrance> entrances;
    private EntityID id;
    private Road endOfPath = null;
    private Road headOfPath = null;
    private double value = 0;
    private List<Area> buildingsOfThisPath;
    private Set<Path> neighbours;
    private Set<Road> orphanRoads;

    private Set<GuideLine> guideLines;//引导线


    public Path() {
        entrances = new ArrayList<>();
        buildingsOfThisPath = new ArrayList<>();
        guideLines = new HashSet<>();
        orphanRoads = new HashSet<>();
    }

    public double getValue() {
        return value;
    }

    public void setId() {
        this.id = getMiddleArea();
    }

    public EntityID getId() {
        return id;
    }

    public Road getEndOfPath() {
        return endOfPath;
    }

    public void setEndOfPath(Road endOfPath) {
        this.endOfPath = endOfPath;
    }

    public Road getHeadOfPath() {
        return headOfPath;
    }

    public void setHeadOfPath(Road headOfPath) {
        this.headOfPath = headOfPath;
    }

    public void addEntrance(Entrance entrance) {//path中 建筑物的入口
        this.entrances.add(entrance);
        List<Building> buildings = entrance.getBuildings();
        buildingsOfThisPath.addAll(buildings);
    }

    public List<Entrance> getEntrances() {//返回path中建筑物的入口
        return entrances;
    }

    public List<Area> getBuildings() {
        return buildingsOfThisPath;
    }

    public Set<Path> getNeighbours() {
        return neighbours;
    }

    public void setNeighbours(Set<Path> neighbours) {
        this.neighbours = neighbours;
    }

    public EntityID getMiddleArea() {
        return this.get((this.size() / 2)).getID();
    }

    public Road getMiddleRoad() {
        return this.get((this.size() / 2));
    }


    public boolean equals(Path other) {
        return getId().equals(other.getId());
    }

    @Override
    public int compareTo(Object o) {
        return Double.compare(((Path) o).getValue(), value);

    }

    @Override
    public String toString() {
        return "Path[id:" + getMiddleRoad().getID() + " v:" + value + "]";
    }


    public Set<GuideLine> getGuideLines() {
        return guideLines;
    }

    public void addOrphanRoad(Road road) {
        orphanRoads.add(road);
    }

    public boolean isOrphanRoad(Road road){
        return orphanRoads.contains(road);
    }

}

